package com.dream.mqpushserver.netty2;

import com.dream.mqpushserver.common.RequestCommand2;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

public class RpcEnCoder extends MessageToByteEncoder<RequestCommand2> {
    @Override
    protected void encode(ChannelHandlerContext ctx, RequestCommand2 msg, ByteBuf out) throws Exception {

        if (msg == null ){
            System.err.println("[RpcEnCoder] encode error , the data is null ");
            return;
        }
        out.writeByte(msg.getType());
        out.writeInt(msg.getBytes().length);
        out.writeBytes(msg.getBytes());
        System.out.println("encode done");
    }
}
